package com.vitalfit.repository;

import com.vitalfit.enums.FitnessPlanTypeEnum;
import com.vitalfit.enums.OrderStateEnum;
import com.vitalfit.model.entity.fitness.FitnessPlan;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.time.LocalDate;
import java.util.List;

@Repository
public interface FitnessPlanRepository extends JpaRepository<FitnessPlan, Integer> {
    @Query("SELECT fp.id FROM FitnessPlan fp WHERE fp.orderStateEnum = :orderStateEnum and fp.customer.id = :customerId")
    List<Long> findFitnessPlanByCustomerAndOrderStateEnum(OrderStateEnum orderStateEnum, Integer customerId);

    @Query("SELECT fp.customer.email FROM FitnessPlan fp WHERE fp.expirationDate BETWEEN :today AND :inSevenDays")
    List<String> findCustomerEmailsByExpiringPlans
            (@Param("today") LocalDate today, @Param("inSevenDays") LocalDate inSevenDays);

    @Query("SELECT fp.planType FROM FitnessPlan fp WHERE  fp.customer.id = :customerId order by fp.startDate limit 1")
    FitnessPlanTypeEnum findFitnessPlanByCustomer(Integer customerId);

    @Query("SELECT fp FROM FitnessPlan fp WHERE fp.customer.id = :customerId")
    List<FitnessPlan> findFitnessPlanByCustomerId(Integer customerId);

}

